package org.example.trancdemo.controller;

import org.example.trancdemo.model.UserInfo;
import org.example.trancdemo.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/trans")
@RestController
public class TransactionalController {
    @Autowired
    private UserInfoService userInfoService;
    @Transactional
    @RequestMapping("/registry")
    public String registry(UserInfo userInfo){
        //⽤⼾注册
        userInfoService.registryUser(userInfo);

        // ⼿动回滚事务
        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();

        return "注册成功";
    }
}
